package 招聘.华为.p1;

        import java.util.*;

public class Main {
    public static void main(String[] args) {
        String s = new Scanner(System.in).nextLine();
        int A_start = -1, A_end = -1, B_start = -1, B_end = -1;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (A_start == -1 && c == '{') {
                A_start = i;
            }
            if (A_end == -1 && c == '}') {
                A_end = i;
            }
            if (A_start != -1 && c == '{') {
                B_start = i;
            }
            if (A_end != -1 && c == '}') {
                B_end = i;
            }
        }
        int r_number_start = s.lastIndexOf("=");
        int R = Integer.valueOf(s.substring(r_number_start + 1));
        String A_String = s.substring(A_start + 1, A_end);
        String B_String = s.substring(B_start + 1, B_end);
        String[] A_number_Strings = A_String.split(",");
        String[] B_number_Strings = B_String.split(",");
        Vector<Integer> A_vec = new Vector<>(), B_vec = new Vector<>();
        for (String num_String : A_number_Strings
        ) {
            A_vec.add(Integer.valueOf(num_String));
        }
        for (String num_String : B_number_Strings
        ) {
            B_vec.add(Integer.valueOf(num_String));
        }
        System.out.println(R);
        System.out.println(A_vec);
        System.out.println(B_vec);
        Integer[] A = new Integer[A_vec.size()], B = new Integer[B_vec.size()];
        A = A_vec.toArray(A);
        B = B_vec.toArray(B);
        System.out.println(Arrays.toString(A));
        System.out.println(Arrays.toString(B));
        Vector<TreeMap<Integer, Integer>> v = new Vector<>();
        for (int i = 0; i < A.length; i++) {
            TreeMap<Integer, Integer> tm = new TreeMap<>();
            for (int j = 0; j < B.length; j++) {
                if (B[j] - A[i] > 0)
                    tm.put(B[j] - A[i], B[j]);
            }
            v.add(tm);
        }
        Vector<Integer[]> m = new Vector<>();
        for (int i = 0; i < A.length; i++) {
            for (Map.Entry<Integer, Integer> entry : v.get(i).entrySet()) {
                if (entry.getKey() <= R) {
                    m.add(new Integer[]{A[i], entry.getValue()});
                }
            }
        }
/*        for (int i = 0; i < A.length; i++) {
            if (!m.containsKey(A[i])) {
                if (v.get(i).entrySet().size() != 0)
                    for (Map.Entry<Integer, Integer> entry : v.get(i).entrySet()) {
                        m.put(A[i], entry.getValue());
                        break;
                    }
            }
        }*/
        for (int i = 0; i < m.size(); i++) {
            System.out.print("(" + m.get(i)[0] + "," + m.get(i)[1]+ ")");
        }
    }
}
